import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn,CreateDateColumn } from 'typeorm';
import { User } from './user.entity';
import { Coupon } from './coupon.entity';

export enum UserCouponStatus {
  UNUSED = 'UNUSED',
  USED = 'USED',
  EXPIRED = 'EXPIRED'
}

@Entity('user_coupon')
export class UserCoupon {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @ManyToOne(() => Coupon)
  @JoinColumn({ name: 'coupon_id' })
  coupon: Coupon;

  @Column({
    type: 'enum',
    enum: UserCouponStatus,
    default: UserCouponStatus.UNUSED
  })
  status: UserCouponStatus;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  receivedAt: Date;

  @Column({ type: 'timestamp', nullable: true })
  usedAt: Date;

  @Column({ type: 'timestamp', nullable: true })
  expiredAt: Date;
}